home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15134 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.cern.ch!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Jobs running under Unix.
  5. Date: 17 Apr 96 12:13:00 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.829743180@news.cern.ch>
  8. References: <829283553snz@tarik.demon.co.uk>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=US-ASCII
  12. Content-Transfer-Encoding: 7bit
  13. X-Newsreader: NN version 6.5.0 #7 (NOV)
  14.  
  15. In <829283553snz@tarik.demon.co.uk> Laurence Barea <larry@tarik.demon.co.uk> writes:
  16.  
  17. >Is there anyone who knows how to tell whether a job is running under Unix
  18. >from within a C program.
  19. >
  20. >e.g. how do I stop a program from running more than once ?
  21.  
  22. Since a non-Unix specific answer exists, I won't send you to 
  23. comp.unix.programmer, where Unix-specific questions should be posted
  24. (but only after reading the comp.unix.questions FAQ).
  25.  
  26. Use a lock file.  If the lock file exists, issue an explanatory message
  27. and exit.  Otherwise, create the lock file and go on.
  28.  
  29. The method is far from perfect, but can be improved.  For example,
  30. using a lock directory instead of a lock file will eliminate a possible
  31. race condition under Unix.
  32.  
  33. Dan
  34. --
  35. Dan Pop
  36. CERN, CN Division
  37. Email: danpop@mail.cern.ch 
  38. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  39.